<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <title>客户产品分类</title>
    <script src="../../../static/kaige/js/szload.js"></script>
    <style>
        .layui-table-cell {
            height: auto;
        }
    </style>
</head>
<body>
<div class="kaige-body">
    <table class="layui-table" id="pageTable" lay-filter="pageTable" lay-size="sm"></table>
    <input type="hidden" name="keywordsCache" value="{}"/>
</div>

<script>
    load_init_js(function () {
        layui.config({
            base: szoapcpath + '/static/kaige/layuiextend/'
        }).use(['element', 'table', 'form', 'layer', 'kaige', 'glfiles'], function () {
            var element = layui.element,
                layer = layui.layer,
                table = layui.table,
                form = layui.form,
                kaige = layui.kaige,
                glfiles = layui.glfiles,
                $ = layui.$;
            form.render();

            //系统默认图片
            window.default_image = szoapcpath + "/static/img/default.png";
            //查看图片
            window.viewImage = function (imgUrl) {
                kaige.viewimage({maxwidth: 600, maxheight: 600, url: imgUrl});
            }

            kaige.table({
                elem: '#pageTable',
                url: "/crm.product_type/index",
                id: 'pageTable',
                toolbar: '#dtoolbar',
                defaultToolbar: ['filter'],
                cols: [[
                    {field: 'id', title: '', align: 'center'},
                    {field: 'name', title: '分类名称', align: 'center'},
                    {field: 'image', title: '分类图片', align: 'center', templet: '#tupian'},
                    {field: 'create_time', title: '创建时间', align: 'center'},
                    {field: 'update_time', title: '更新时间', align: 'center'},
                    {title: '操作', toolbar: '#dtrbar', align: 'center', width: 150, fixed: 'right'}
                ]]
            });

            function getsearchform() {
                var gfv = {
                    "keywords": $('#keywords').val(),
                }
                gfv.rnd = Math.random();
                return gfv;
            }

            window.searchAction = function () {
                var where = getsearchform();
                if (JSON.stringify(where) == "{}") {
                    layer.msg('当前没有筛选条件！');
                    return;
                }
                setTimeout(function () {
                    //执行重载
                    table.reload('pageTable', {
                        height: 'full-30'  //必须写，有时候高度不出来
                        , page: {curr: 1} //置第一页
                        , where: where
                    });
                    $("#keywords").val(where['keywords']);
                }, 300);
            }

            //列表-监听表头工具栏事件dtoolbar
            table.on('toolbar(pageTable)', function (obj) {
                switch (obj.event) {
                    case 'btn-add':
                        btnadd();
                        break;
                    case 'btn-search':
                        searchAction();
                        break;
                }
            });

            //列表-监听单元格行工具事件dtrbar
            table.on('tool(pageTable)', function (obj) {
                var that = this;
                var data = obj.data;
                switch (obj.event) {
                    case 'edit':
                        baredit(data);
                        break;
                    case 'del':
                        bardel(data);
                        break;
                }
            });

            //添加
            function btnadd() {
                kaige.form({
                    url: "/crm.product_type/add",
                    data: {},
                    id: 'kaige',
                    area: ['750px', '450px'],
                    title: '<i class="layui-icon layui-icon-add-circle"></i> 添加 - 客户产品分类',
                    tablelayid: 'pageTable',
                    overflow: false,
                    encode: 1,
                    callbefore: function (layero, index) {

                    },
                    postbefore: function (updata) {
                        updata.files_id = updata.form_files_id;
                        delete updata.form_files_id;
                        return updata;
                    },
                    getdata: function (res) {
                        var data = (res && res.data && res.data.fi) ? res.data.fi : null;
                        glfiles.form({
                            id: 'form',
                            is_edit: true,
                            data: data
                        });
                    }
                });
            }

            //编辑
            function baredit(d) {
                kaige.form({
                    url: "/crm.product_type/edit",
                    data: {id: d.id},
                    id: 'kaige',
                    area: ['750px', '450px'],
                    title: '<i class="layui-icon layui-icon-edit"></i> 编辑 - 客户产品分类',
                    tablelayid: 'pageTable',
                    overflow: false,
                    encode: 1,
                    callbefore: function (layero, index) {

                    },
                    postbefore: function (updata) {
                        updata.files_id = updata.form_files_id;
                        delete updata.form_files_id;
                        return updata;
                    },
                    getdata: function (res) {
                        var data = (res && res.data && res.data.fi) ? res.data.fi : null;
                        glfiles.form({
                            id: 'form',
                            is_edit: true,
                            data: data
                        });
                    }
                });
            }

            //删除
            function bardel(d) {
                layer.confirm('您确定删除吗？', {
                    title: '<i class="layui-icon layui-icon-delete"></i> 删除确认',
                    btn: ['确认', '取消']
                }, function () {
                    $.post("/crm.product_type/del", {id: d.id}, function (res) {
                        res.status && table.reload('pageTable');
                        layer.msg(res.msg);
                    });
                });
            };

        });
    });
</script>
<script type="text/html" id="dtrbar">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i>
        </button>
        <button class="layui-btn layui-btn-xs" lay-event="del" title="删除"><i class="layui-icon layui-icon-delete"></i>
        </button>
    </div>
</script>

<script type="text/html" id="dtoolbar">
    <div class="layui-btn-container layui-form filter-form" lay-filter="searchform">
        <div class="layui-inline">
            <input class="layui-input tsinput" name="keywords" placeholder="关键字" id="keywords">
            <button class="tsbutton" lay-event="btn-search" id="btn-search" title="筛选">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </div>

        <div class="layui-btn-group">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-add" style="margin-top:2px;"><i
                    class="layui-icon layui-icon-add-circle"></i> 添加
            </button>
        </div>
    </div>
</script>

<script type="text/html" id="tupian">
    <div class="userinfotitle">
        <div class="uif-avatar">
            <a href="javascript:void(0);" onclick="viewImage('{{ d.files_id }}')">
                <img src="{{ d.files_id }}" class="list_avatar1" alt="" width="50px" height="50px"/>
            </a>
        </div>
    </div>
</script>
<script type="text/html" id="kaige_form_html">
    <form class="layui-form layui-form-pane kaige-body-form" style="padding: 5px;" lay-filter="kaige_form_lay_filter">
        {{# if(d.id){ }}
        <input type="hidden" name="id" value="{{ d.id }}"/>
        {{# } }}
        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-block">
                <input name="name" value="{{ d.name || '' }}" class="layui-input" type="text">
            </div>
        </div>

        <div class="layui-form-item" id="form_files_gl_html"></div>

        <div class="layui-form-item layui-hide">
            <button class="layui-hide" lay-submit="" id="kaige_form_btn_save" lay-filter="kaige_form_btn_save">保存数据
            </button>
        </div>
    </form>
</script>
</body>

</html>